package com.ruoyi.wechat.api;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.wechat.domain.CFacilityType;
import com.ruoyi.wechat.domain.WxCampFacilityVo;
import com.ruoyi.wechat.service.IWxFacilityTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "微信设施", tags = {"微信设施"})
@RestController
@RequestMapping("/wechat/facilityType")
public class WxFacilityTypeController extends BaseController {

    @Autowired
    private IWxFacilityTypeService wxFacilityTypeService;


//    查询设施列表

    @ApiOperation("微信设施查询")
    @GetMapping("/list")
    public TableDataInfo list(CFacilityType cFacilityType)
    {
        List<CFacilityType> list = wxFacilityTypeService.selectCFacilityByFacilityTypeId(cFacilityType);
        System.out.println("返回值"+list);
        return getDataTable(list);
    }
    //添加营地对应的营地设施
    @ApiOperation("微信新增营地对应的设施")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WxCampFacilityVo wxCampFacilityVo){
        if (wxCampFacilityVo.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (wxCampFacilityVo.getFacilityIds() == null) {
            return error("服务设施Id不能为空");
        }
        return toAjax(wxFacilityTypeService.insertCampFacility(wxCampFacilityVo.getCampId(), wxCampFacilityVo.getFacilityIds()));
    }

//  根据营地Id查询该营地的服务设施列表
    @ApiOperation(value = "根据营地Id查询该营地的服务设施列表")
    @GetMapping("/getInfo/{campId}")
    public AjaxResult getInfo(@PathVariable("campId") String campId) {
        if (campId == null) {
            return error("营地Id不能为空");
        }
        List<CFacilityType> list = wxFacilityTypeService.campFacilityListByCampId(campId);
        return success(list);
    }
//根据营地Id删除服务设施
    @DeleteMapping("/delete/{campId}")
    public AjaxResult delete(@PathVariable("campId") String campId){
        if (campId == null) {
            return error("营地Id不能为空");
        }
        return toAjax(wxFacilityTypeService.deleteCampFacilityByCampId(campId));
    }
}
